<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class OrderController extends Controller
{
   
		//显示订单列表
    public function index(){
        $orders = DB::table('order')->paginate(5);
        return view('admin.order.index', ['orders' => $orders]);
    }
	
	
	
	 //删除订单操作
    public function delete(Request $request){
        //接收用户id
        $oid=$request->input('oid');
        //删除操作
        $result=DB::table('order')->where('oid','=',$oid)->delete();

        if($result){
            echo 1;
        }else{
            echo 0;
        }
    }
	
	
	//更新订单方法
	public function modify(Request $request){
		//获取订单id
		$oid=$request->input('oid');
		//查找订单信息
		$order=DB::table('order')->where('oid','=',$oid)->first();
		//json编码后返回
		return response()->json($order);
		
	}
	
	//更新订单操作
	public function update(Request $request){
		//接受表单信息  更新到数据库
		$order = $request->only('number','phone','addreee');
		$oid = $request->input('oid');
		
		$result = DB::table('order')->where('oid','=',$oid)->update($order);
		
		//判断执行结果
		if($result){
			return success('/admin/order/index','更新订单信息成功',2);
		}else{
			return error('/admin/order/index','更新订单信息失败',2);
		}
	}
	
	
	
	
}
